package simorg.security;

import java.util.ArrayList;
import java.util.Collection;

import org.dom4j.Document;

import simorg.actions.Action;
import simorg.view.ModelView;
import simorg.view.Page;
import simorg.view.WebSessionContext;

public class AccessBarrier extends Action{

	private Collection<SecurityAccess> securityList;
	
	public AccessBarrier() {
		super("accesscheck");
		this.securityList = new ArrayList<SecurityAccess>();
	}
	
	public ModelView process(WebSessionContext wc) throws Exception  {
		for ( SecurityAccess sc : this.securityList ) {
			if ( !sc.isAccessible() ) {
				Document xmlDoc = this.getBaseXml(wc);
				return new ModelView(Page.AccessViolation, xmlDoc);
			}
		}
		return null;
	}
	
	public void addSecurityAccess(SecurityAccess sc) {
		this.securityList.add(sc);
	}
}
